{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=2975
  Verdict: Accepted
}
uses SysUtils;
const eps=1e-16; bad=-11340011; vb=1677117; sup=4365363654; big=maxlongint; small=1e-30;
var n,r,i,j:longint; cur,a,b:int64; c,k,m,g:double; t:array[1..10] of extended; f:boolean;
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(a,b);
t[1]:=a+b;
t[2]:=a-b;
t[3]:=b-a;
t[4]:=a*b;
n:=4;
r:=0;
f:=true;
c:=1;
k:=1;
if b<>0 then begin
  c:=a/b;
  if c=-0 then c:=0;
  inc(n);
  t[n]:=c;
end;
if a<>0 then begin
  k:=b/a;
  if k=-0 then k:=0;
  inc(n);
  t[n]:=k;
end;
if ((a=b) and (b>0)) or ((a=2) and (b=4)) or (a=1) or (b=1) or ((b=2) and (a=4)) or ((a=0) and (b>0)) or ((a>0) and (b=0)) then begin
  if (a=1) or (b=1) then begin
    inc(n,2);
    t[n-1]:=a;
    t[n]:=b;
  end else
  if (a*b<>0) then begin
    inc(n);
    cur:=1;
    for i:=1 to b do begin
      cur:=cur*a;
      if (abs(cur)>a*b) or (abs(cur)>big) then begin
        cur:=bad;
        break;
      end;
    end;
    t[n]:=cur;
  end else begin
    inc(n,2);
    t[n-1]:=1;
    t[n]:=0;
  end;
end else
if (a=b) and (b<0) then begin
  cur:=1;
  for i:=-1 downto b do begin
    cur:=cur*a;
    if abs(1/cur-small)<eps then begin
      cur:=vb;
      break;
    end;
  end;
  inc(n);
  t[n]:=1/cur;
end else
if ((a<0) or (b<0)) and (a*b<>0) then begin
  m:=1;
  g:=1; 
  inc(n,2);
  if b<0 then begin
    if (a=-1) and odd(b) then m:=-1 else
    if (a=-1) and (not odd(b)) then m:=1 else
    if a=1 then m:=1 else
    for i:=-1 downto b do begin
      m:=m*a;
      if abs(1/m-small)<eps then begin
        m:=-vb;
        break;
      end;
    end;
  end else begin
    if (a=-1) and odd(b) then m:=-1 else
    if (a=-1) and (not odd(b)) then m:=1 else
    if a=1 then m:=1 else
    for i:=1 to b do begin
      m:=m*a;
      if abs(m)>big then begin
        m:=-vb;
        break;
      end;
    end;
  end; 
  t[n-1]:=1/m;
  if a<0 then begin
    if (b=-1) and odd(a) then g:=-1 else
    if (b=-1) and (not odd(a)) then g:=1 else
    if b=1 then g:=1 else
    for i:=-1 downto a do begin
      g:=g*b;
      if abs(1/g-small)<eps then begin
        g:=-bad;
        break;
      end;
    end;
  end else begin
    if (b=-1) and odd(a) then g:=-1 else
    if (b=-1) and (not odd(a)) then g:=1 else
    if b=1 then g:=1 else
    for i:=1 to a do begin
      g:=g*b;
      if abs(g)>big then begin
        g:=-bad;
        break;
      end;
    end;
  end;
  t[n]:=1/g;
end else
if (not((a=0) and (b<=0))) and  (not((b=0) and (a<=0))) then  begin
  inc(n,2);
  t[n-1]:=sup;
  t[n]:=-sup;
end else
if ((a=0) and (b<0)) or ((a<0) and (b=0)) then begin
  inc(n);
  t[n]:=1;
end;
for i:=1 to n do begin
  f:=true;
  for j:=i-1 downto 1 do
    if abs(t[i]-t[j])<eps then f:=false;
  if f then inc(r);
end;
write(r);
end.